﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
namespace ZhaoPin.Admin
{
    public partial class ShowDetails : System.Web.UI.Page
    {
        StringBuilder sb;
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["Id"];
            Guid guid = Guid.Empty;
            if (!Guid.TryParse(id, out guid))
            {
                Response.Write("出现错误，请联系管理员");
                Response.End();
            }
            if (!IsPostBack)
            {
                Session["UserId"] = guid;
                Label lbES = FormView1.FindControl("lbES") as Label;
                Label lbWS = FormView1.FindControl("lbWS") as Label;
                Label lbHH = FormView1.FindControl("lbHH") as Label;
                RecruitContainer rc = new RecruitContainer();
                var es = from ess in rc.EduStories where ess.PersonId.Equals(guid) orderby ess.StartDate select ess;
                sb = new StringBuilder();
                if (es.Any())
                {
                    es.ToList().ForEach(es1 => writeOneEduStory(es1));
                    sb.Remove(sb.Length - 5, 5);
                }
                lbES.Text = sb.ToString();
                sb.Clear();
                var ws = from wss in rc.WorkStories where wss.PersonId.Equals(guid) orderby wss.StartDate select wss;
                if (ws.Any())
                {
                    ws.ToList().ForEach(ws1 => writeOneWorkStory(ws1));
                    sb.Remove(sb.Length - 5, 5);
                }
                lbWS.Text = sb.ToString();
                sb.Clear();
                var hh = from hhs in rc.Households where hhs.PersonId.Equals(guid) orderby hhs.RelationCode select hhs;
                if (hh.Any())
                {
                    hh.ToList().ForEach(hh1 => writeOneHousehold(hh1));
                    sb.Remove(sb.Length - 5, 5);
                }
                lbHH.Text = sb.ToString();
                sb.Clear();
                rc.Dispose();
                Image ph=FormView1.FindControl("imagePhoto") as Image;
                if (ph != null) ph.ImageUrl = "~/Admin/ShowPhoto.aspx?id=" + guid.ToString();
            }
        }
        protected void writeOneEduStory(EduStory es)
        {
            paraStart();
            sb.Append(es.StartDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(es.EndDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(es.University);
            appendSpace(2);
            sb.Append(es.Speciality);
            appendSpace(2);
            sb.Append(es.TDictEduLevel.FName);
            appendSpace(2);
            sb.Append(es.TDictDegree.FName);
            appendSpace(2);
            sb.Append(es.TDictEduType.FName);
            appendSpace(2);
            sb.Append(es.TDictEduYear.FName);
            paraEnd();
        }
        protected void writeOneWorkStory(WorkStory ws)
        {
            paraStart();
            sb.Append(ws.StartDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(ws.EndDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(ws.Company);
            appendSpace(2);
            sb.Append(ws.TDictHospitalClass.FName);
            appendSpace(2);
            sb.Append(ws.Post);
            appendSpace(2);
            sb.Append(ws.ProfessionalRank);
            paraEnd();
        }
        protected void writeOneHousehold(Household es)
        {
            paraStart();
            sb.Append(es.Name);
            appendSpace(2);
            sb.Append(es.TDictGender.FName);
            appendSpace(2);
            sb.Append(es.TDictRelation.FName);
            appendSpace(2);
            sb.Append(es.TDictParty.FName);
            appendSpace(2);
            sb.Append(es.Company);
            appendSpace(2);
            sb.Append(es.Headship);
            paraEnd();
        }
        protected void appendSpace(int count)
        {
            for (int i = 0; i < count; i++)
                sb.Append(" ");
        }
        protected void paraStart()
        {
        }
        protected void paraEnd()
        {
            sb.Append("<br/>");
        }
    }
}